<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Pro;
use App\Att;
class CheckController extends Controller
{
    public function prolist(){
        $prolist = Pro::orderBy('pid','desc')->get();
        return view('prolist',['prolist'=>$prolist]);
    }

    public function check($pid){
    	//审核项目,主要是修改projects表和atts表
    	$pro = Pro::find($pid);
    	return view('shenhe',['pro'=>$pro]);
    }

    public function checkPost(Request $req,$pid){
    	$pro = Pro::find($pid);
    	$att = Att::where('pid',$pid)->first();

    	//写入数据库 projects
    	$pro->title = $req->title;//项目名称
    	$pro->hrange = $req->hrange;//借款期限
    	$pro->rate = $req->rate;//百分比
    	$pro->status = $req->status;//审核结果


    	//写入数据库 附属表 atts
    	$att->title = $req->title;//项目名称
    	$att->realname = $req->realname;//真实姓名
    	$att->gender = $req->gender;//性别
    	$att->age = $req->age; //年龄
    	$att->udesc = $req->udesc;//借款人基本信息
    	$att->salary = $req->salary;//月收入

    	if($pro->save() && $att->save()){
    		return redirect('/prolist');
    	}else{
    		return 'error';
    	}
    }
    
}
